package com.ruoyi.web.controller.edh;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.edh.domain.EdhFollow;
import com.ruoyi.edh.domain.model.EdhFollowModel;
import com.ruoyi.edh.service.IEdhFollowService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 易订货-学院关注Controller
 *
 * @author xxx
 * @date 2020-09-02
 */
@RestController
@RequestMapping("/edh/follow")
@Api(description = "易订货-学院关注")
public class EdhFollowController extends BaseController {
    @Autowired
    private IEdhFollowService edhFollowService;

    /**
     * 查询易订货-学院关注列表
     */
    @GetMapping("/list")
    @ApiOperation("易订货-学院关注列表")
    public TableDataInfo list(EdhFollow edhFollow) {
        startPage();
        List<EdhFollow> list = edhFollowService.selectEdhFollowList(edhFollow);
        return getDataTable(list);
    }

    /**
     * 查询用户关注与粉丝情况
     */
    @GetMapping("/followAndFans")
    @ApiOperation("查询用户关注与粉丝情况")
    @ApiImplicitParam(name = "useurId", value = "用户id", required = true, dataType = "Long")
    public AjaxResult followAndFans(Long userId) {
        return AjaxResult.success(edhFollowService.followAndFans(userId));
    }


    /**
     * 学院推荐
     */
    @GetMapping("/collegeRecommend")
    @ApiOperation("学院推荐")
    public AjaxResult collegeRecommend() {
        return AjaxResult.success(edhFollowService.collegeRecommend());
    }

    /**
     * 导出易订货-学院关注列表
     */
    @Log(title = "易订货-学院关注", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    @ApiOperation("导出易订货-学院关注列表")
    public AjaxResult export(EdhFollow edhFollow) {
        List<EdhFollow> list = edhFollowService.selectEdhFollowList(edhFollow);
        ExcelUtil<EdhFollow> util = new ExcelUtil<EdhFollow>(EdhFollow.class);
        return util.exportExcel(list, "follow");
    }

    /**
     * 获取易订货-学院关注详细信息
     */
    @GetMapping
    @ApiOperation("获取易订货-学院关注详细信息")
    public AjaxResult getInfo(Long id) {
        return AjaxResult.success(edhFollowService.selectEdhFollowById(id));
    }

    /**
     * 关注/取关
     */
    @Log(title = "易订货-学院关注", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("关注/取关")
    public AjaxResult add(@Validated @RequestBody EdhFollowModel.Insert edhFollow) {
        if (edhFollow.getUserId().equals(SecurityUtils.getUserId())) {
            return AjaxResult.error("您在自恋的道路上已经无敌了");
        }
        int i = edhFollowService.insertEdhFollow(edhFollow);
        return AjaxResult.success(0 == i ? "取关成功" : "关注成功");
    }

    /**
     * 修改易订货-学院关注
     */
    @Log(title = "易订货-学院关注", businessType = BusinessType.UPDATE)
    @PutMapping
    //@ApiOperation("修改易订货-学院关注") 此接口暂时不用
    public AjaxResult edit(@RequestBody EdhFollow edhFollow) {
        return toAjax(edhFollowService.updateEdhFollow(edhFollow));
    }

    /**
     * 删除易订货-学院关注
     */
    @Log(title = "易订货-学院关注", businessType = BusinessType.DELETE)
    @DeleteMapping
    @ApiOperation("删除易订货-学院关注")
    public AjaxResult remove(Long[] ids) {
        return toAjax(edhFollowService.deleteEdhFollowByIds(ids));
    }
}
